package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.api.ApiController;

import javax.validation.Valid;
import java.util.Arrays;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Slf4j
@AllArgsConstructor
@RequestMapping("/${controllerMappingHyphen}")
@Api(value = "${table.controllerName}", tags = "${table.controllerName}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
        @Autowired
        private ${table.serviceName} ${table.serviceName?uncap_first};
       /**
       * 列表
       * @param pageNum
       * @param pageSize
       * @param ${entity?uncap_first}
       * @return
       */
       @GetMapping("/list")
       @ApiOperation(value = "列表", notes = "传入${entity}对象")
       public R<IPage${"<"+entity+">"}> list(Integer pageNum, Integer pageSize,${entity} ${entity?uncap_first}) {
            QueryWrapper<${entity}> queryWrapper=new QueryWrapper<>(${entity?uncap_first});
            queryWrapper.groupBy("update_time_");
            IPage<${entity}> page = ${table.serviceName?uncap_first}.page(new Page<>(pageNum, pageSize), queryWrapper);
            return R.ok(page);
       }
       /**
       *
       * @param id
       * @return
       */
       @GetMapping("/{id}")
       @ApiOperation(value = "详情", notes = "传入id")
       public R<${entity}> view(@PathVariable("id") String id) {
          ${entity} user = ${table.serviceName?uncap_first}.getById(id);
          return R.ok(user);
        }

        /**
        * 新增
        * @param ${entity?uncap_first}
        * @return
        */
        @PostMapping
        @ApiOperation(value = "新增", notes = "传入${entity}")
        public R add(@Valid @RequestBody ${entity} ${entity?uncap_first}) {
          return this.success(${table.serviceName?uncap_first}.save(${entity?uncap_first}));
        }


        /**
        * 修改
        * @param ${entity?uncap_first}
        * @return
        */
        @PutMapping
        @ApiOperation(value = "修改", notes = "传入${entity}")
        public R edit(@Valid @RequestBody ${entity} ${entity?uncap_first}) {
          return this.success(${table.serviceName?uncap_first}.updateById(${entity?uncap_first}));
        }

        /**
        * 删除
        */
        @DeleteMapping("/{ids}")
        @ApiOperation(value = "删除", notes = "传入ids")
        public R del(@ApiParam(value = "主键集合", required = true) @PathVariable("ids") String[] ids) {
          return this.success(${table.serviceName?uncap_first}.removeByIds(Arrays.asList(ids)));
        }
 }
</#if>
